import java.util.logging.Logger;
import src.de.checker.hochzeit.domain.util.*;
import src.de.checker.hochzeit.domain.user.*;
import src.de.checker.hochzeit.konstanten.*
import com.google.appengine.api.datastore.*
import static com.google.appengine.api.datastore.FetchOptions.Builder.*

Logger log = Logger.getLogger('StammdatenController');


if(params?.index ==~ /(?i)true/)
{
	def query = new Query(Konstanten.KATEGORIE)
	PreparedQuery preparedQuery = datastore.prepare(query)
 	def entities = preparedQuery.asList( withLimit(100) )
	request['listkat'] = entities
	
	def query1 = new Query(Konstanten.ROLLE)
	PreparedQuery preparedQuery1 = datastore.prepare(query1)
 	def entities1 = preparedQuery1.asList( withLimit(100) )
	request['listrole'] = entities1
	
	def query2 = new Query(Konstanten.TT)
	PreparedQuery preparedQuery2 = datastore.prepare(query2)
 	def entities2 = preparedQuery2.asList( withLimit(100) )
	request['listtt'] = entities2
	
	forward '/admin/createstamm.gtpl'
}

if(params?.createkat ==~ /(?i)true/)
{
	Entity entity = new Entity(Konstanten.KATEGORIE)
	entity['id'] = new Integer(params.id)
	entity['bezeichnung'] = params.bezeichnung
	entity.save()
	redirect '/admin/createstamm'
}
if(params?.createrolle ==~ /(?i)true/)
{
	Entity entity = new Entity(Konstanten.ROLLE)
	entity['id'] = new Integer(params.id)
	entity['bezeichnung'] = params.bezeichnung
	entity.save()
	redirect '/admin/createstamm'
}
if(params?.creatett ==~ /(?i)true/)
{
	Entity entity = new Entity(Konstanten.TT)
	entity['id'] = new Integer(params.id)
	entity['bezeichnung'] = params.bezeichnung
	entity.save()
	redirect '/admin/createstamm'
}